home *** CD-ROM | disk | FTP | other *** search
- From: clamage@Eng (Steve Clamage)
- Message-ID: <4h784m$alj@engnews1.Eng.Sun.COM>
- X-Original-Date: 1 Mar 1996 16:20:38 GMT
- Path: in1.uu.net!bounce-back
- Date: 04 Mar 96 14:26:34 GMT
- Approved: fjh@cs.mu.oz.au
- Newsgroups: comp.std.c++
- Subject: Re: Streams and eof()
- Organization: Sun Microsystems Inc.
- References: <4h5qp0$6di@engnews1.Eng.Sun.COM>
- Reply-To: clamage@Eng
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBFAgUBMTr9suEDnX0m9pzZAQHcawF/c7WLyJK7jLn9mxMJJlMTGXWmAXnK+PvH
- tIMdbj2ef14VNnvSzGG2UGoTtjrcWvPi
- =Z6h/
-
- In article 6di@engnews1.Eng.Sun.COM, axl@zedat.fu-berlin.de (Axel Thimm)
- writes:
-
- >Hello,
- >
- >I have had a look in the April draft, but I think that there is a small
- >ambiguity about eof() methods in streams.
- >Is the eof-flag raised, when the end of the stream is reached, or when
- >an attempt to move past this end is made?
-
- It is deliberately not specified in detail, the same situation as with
- C stdio, and for the same reasons.
-
- If the eof flag has been set, it means that the end of the file has been
- seen and that no more characters are available. It doesn't necessarily
- mean that you have attempted to read beyond the end yet. If the flag is
- not set, it doesn't mean that more characters are available.
-
- The reason for the looseness in the definition is to allow for different
- kinds of input devices. From a pipe or keyboard, you don't know whether
- eof has been reached until you get a positive indication of eof. If no
- more characters are currently available, you don't know whether you are
- at eof until the next input item shows up (a character or an EOF). A
- test like
- if( cin.eof() ) ...
- could wait indefinitely under such circumstances.
-
- Standard Pascal, by contrast, requires predictive I/O. The file variable
- always contains the next available data or EOF. That is a nice model of
- I/O, but causes a problem for devices like keyboards and pipes: the
- program waits during file opening until input is available. (The program
- hangs during intialization until the user types something at the keyboard.)
- Consequently, most Pascal implementations don't follow the standard for
- console input, but use "lazy I/O" instead.
-
- ---
- Steve Clamage, stephen.clamage@eng.sun.com
- ---
- [ To submit articles: try just posting with your news-reader.
- If that fails, use mailto:std-c++@ncar.ucar.edu
- FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
- Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
- Comments? mailto:std-c++-request@ncar.ucar.edu.
- ]
-